{include file="public/head"}
{include file="public/left"}
<!-- content -->

<div class="main_02_r">

    <!--内容区域-->
    <div class="site_01">
        <span>当前位置：</span><a href="#">城事社</a><i>></i><a href="#">分类管理</a><i>></i><a href="#">便民号薄</a>
    </div>

    <div class="nrq_01">
        <div class="gg_01">
            <span><a href="{:url('classify/index')}">信息分类</a></span><span class="on">便民号薄</span>
        </div>
        <div class="gg_02">
            <div class="gg_03">

                <div class="hbgl_01">
                    <div class="fl">
                        <a href="javascript:void(0);" class="on tjfl_click">添加分类</a>
                    </div>
                </div>

                <div class="xxfl_01">
                    <table cellpadding="0" cellspacing="0">
                        <tr>
                            <th>序号</th>
                            <th>分类名称</th>
                            <th>排序</th>
                            <th>显隐</th>
                            <th>操作</th>
                        </tr>
                        {volist name="arr" id="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td class="td_add">
                                <em class="em_add">
                                    <input type="text" value="{$vo.classify_name}" class="xxfl_01_txt" id="edit_{$vo.id}" />
                                    <input type="button" value="" onclick="ajax_edit('{$vo.id}')" class="xxfl_01_btn" />
                                </em>
                            </td>
                            <td class="em_px">
                                <em class="em_px">
                                    <input type="button" class="xxfl_px_01" onclick="ajax_sort(0,'{$vo.order_by}')" value="" />
                                    <input type="button" class="xxfl_px_02" onclick="ajax_sort(1,'{$vo.order_by}')" value="" />
                                </em>
                            </td>
                            <td class="td7 flxx_click">
                                <em value="{$vo.id}" class="{if condition='$vo.show_flag == 0'}on{/if}"><b></b></em>
                            </td>
                            <td>
                                <a href="{:url('classify/details',array('id'=>$vo.id))}" class="a_cz">详情</a>
                                <a href="javascript:ajax_index_delete('{$vo.id}');" class="a_cz">删除</a>
                            </td>
                        </tr>
                        {/volist}
                    </table>
                </div>
                <script type="text/javascript">
                    $(".flxx_click").each(function () {
                        $(this).find("em").click(function () {
                            var id = $(this).attr('value');
                            if ($(this).attr("class") != "on") {
                                $(this).addClass("on");
                                $.ajax({
                                    url:"{:url('classify/ajax_show_flag')}",
                                    type: "POST",//方法类型
                                    // dataType: "json",//预期服务器返回的数据类型
                                    data: {"id":id,"show_flag":0},
                                    success: function (data) {
                                        if (data.code === 1) {

                                            layer.msg("<span style='margin-left: 18px;'>"+data.msg+"</span>",{icon: 1,time:1000},function(){
                                                if(data.data.num !=1){
                                                    window.location.href=data.url;
                                                }

                                            });
                                        }else{
                                            layer.msg("<span style='margin-left: 18px;'>"+data.msg+"</span>",{icon: 2,time:1000},function(){
                                                if(data.url){
                                                    window.location.href=data.url;
                                                }else{
                                                    location.reload();
                                                }
                                            });
                                        }
                                    },
                                    error : function() {
                                        layer.msg("<span style='margin-left: 18px;'>请求错误,请联系管理员</span>",{icon: 0,time:1000},function(){
                                            location.reload();
                                        });
                                    }
                                });
                            }
                            else
                            {
                                $(this).removeClass("on");
                                $.ajax({
                                    url:"{:url('classify/ajax_show_flag')}",
                                    type: "POST",//方法类型
                                    // dataType: "json",//预期服务器返回的数据类型
                                    data: {"id":id,"show_flag":1},
                                    success: function (data) {
                                        if (data.code === 1) {

                                            layer.msg("<span style='margin-left: 18px;'>"+data.msg+"</span>",{icon: 1,time:1000},function(){
                                                if(data.data.num !=1){
                                                    window.location.href=data.url;
                                                }

                                            });
                                        }else{
                                            layer.msg("<span style='margin-left: 18px;'>"+data.msg+"</span>",{icon: 2,time:1000},function(){
                                                if(data.url){
                                                    window.location.href=data.url;
                                                }else{
                                                    location.reload();
                                                }
                                            });
                                        }
                                    },
                                    error : function() {
                                        layer.msg("<span style='margin-left: 18px;'>请求错误,请联系管理员</span>",{icon: 0,time:1000},function(){
                                            location.reload();
                                        });
                                    }
                                });
                            }
                        });
                    });
                </script>
                <div class="gg_03_b">
                    <div class="fl">
                        <span>共 <i>{$arr->total()}</i> 条</span><span>每页 <i>{$arr->listRows()}</i> 条</span>
                    </div>
                    <div class="fr">
                        {$arr->render()}
                    </div>
                </div>

            </div>
        </div>

    </div>

</div>

<!--添加分类弹窗-->
<div class="tjfl_fr">
    <div class="ggtcxq_bg"></div>
    <div class="ggtcxq_c">
        <div class="ggtcxq_cfr">
            <div class="ggtcxqc_t">
                <span>添加分类</span><a href="javascript:void(0);" class="close"></a>
            </div>
            <div class="tjfl_c">
                <form class="ajax_index_first_form" action="{:url('classify/ajax_directory_first')}">
                    <p>
                        <span>分类名称</span>
                        <input type="text" name="classify_name" class="tjflc_txt" />
                    </p>
                    <p>
                        <span>&nbsp;</span>
                        <input type="button" value="确定" class="tjflc_btn ajax_index_first_submit" />
                    </p>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(".tjfl_click").each(function () {
        $(this).click(function () {
            $(".tjfl_fr").show();
            $(".tjfl_fr .ggtcxq_c").css({ "margin-top": "-" + $(".tjfl_fr .ggtcxq_c").height() / 2 + "px" });
        });
    });
    $(".tjfl_fr .close").click(function () {
        $(".tjfl_fr").hide();
    });
    $(".tjfl_fr .ggtcxq_bg").click(function () {
        $(".tjfl_fr").hide();
    });
</script>

<!--添加子类弹窗-->
<div class="tjzl_fr">
    <div class="ggtcxq_bg"></div>
    <div class="ggtcxq_c">
        <div class="ggtcxq_cfr">
            <div class="ggtcxqc_t">
                <span>添加子类</span><a href="javascript:void(0);" class="close"></a>
            </div>
            <div class="tjfl_c">
                <p>
                    <span>一级分类</span>
                    <select><option>请选择一项</option></select>
                </p>
                <p>
                    <span>子类名称</span>
                    <input type="text" class="tjflc_txt" />
                </p>
                <p>
                    <span>&nbsp;</span>
                    <input type="button" value="确定" class="tjflc_btn" />
                </p>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(".tjzl_click").each(function () {
        $(this).click(function () {
            $(".tjzl_fr").show();
            $(".tjzl_fr .ggtcxq_c").css({ "margin-top": "-" + $(".tjzl_fr .ggtcxq_c").height() / 2 + "px" });
        });
    });
    $(".tjzl_fr .close").click(function () {
        $(".tjzl_fr").hide();
    });
    $(".tjzl_fr .ggtcxq_bg").click(function () {
        $(".tjzl_fr").hide();
    });
</script>
<script type="text/javascript">

    $(function(){
        var layer = layui.layer,form = layui.form;
        //添加一级分类
        $(".ajax_index_first_submit").click(function(){
            var url = $('.ajax_index_first_form').attr("action")?$('.ajax_index_first_form').attr("action"):"{:url()}";
            var data = $('.ajax_index_first_form').serialize();
            ajax_psot(url,data);
        });
    })

    function ajax_edit(id){
        var classify_name = $("#edit_"+id).val();
        $.ajax({
            url: "{:url('classify/ajax_index_edit')}",
            type: "POST",//方法类型
            // dataType: "json",//预期服务器返回的数据类型
            data: {"id":id,"classify_name":classify_name},
            success: function (data) {
                if (data.code === 1) {
                    layer.msg("<span style='margin-left: 18px;'>" + data.msg + "</span>", {
                        icon: 1,
                        time: 1000
                    }, function () {
                        /*window.location.href = data.url;*/
                    });
                } else {
                    layer.msg("<span style='margin-left: 18px;'>" + data.msg + "</span>", {
                        icon: 2,
                        time: 1000
                    }, function () {
                        /*if(data.url){
                        window.location.href=data.url;
                    }else{
                        location.reload();
                    }*/
                    });
                }
            },
            error: function () {
                layer.msg("<span style='margin-left: 18px;'>请求错误,请联系管理员</span>", {
                    icon: 0,
                    time: 1000
                }, function () {
                    //location.reload();
                });
            }
        });
    }

    function ajax_sort(type,order_by){
        ajax_psot("{:url('classify/ajax_directory_sort')}",{"type":type,"order_by":order_by})
    }

    function ajax_index_delete(id){
        ajax_psot("{:url('classify/ajax_index_delete')}",{"id":id})
    }

    function ajax_psot(url,data){
        $.ajax({
            url:url,
            type: "POST",//方法类型
            // dataType: "json",//预期服务器返回的数据类型
            data: data,
            success: function (data) {
                if (data.code === 1) {
                    layer.msg("<span style='margin-left: 18px;'>"+data.msg+"</span>",{icon: 1,time:1000},function(){
                        window.location.href=data.url;
                    });
                }else{
                    layer.msg("<span style='margin-left: 18px;'>"+data.msg+"</span>",{icon: 2,time:1000},function(){
                        /*if(data.url){
                            window.location.href=data.url;
                        }else{
                            location.reload();
                        }*/
                    });
                }
            },
            error : function() {
                layer.msg("<span style='margin-left: 18px;'>请求错误,请联系管理员</span>",{icon: 0,time:1000},function(){
                    //location.reload();
                });
            }
        });
    }
</script>

<!-- content -->
{include file="public/foot"}